package com.appforged.AppForged;

import com.appforged.AppForged1.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class Splash extends Activity {

	MediaPlayer ourSong;

	@Override
	protected void onCreate(Bundle splashBundle) {
		// TODO Auto-generated method stub
		super.onCreate(splashBundle);
		setContentView(R.layout.splash);

		ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
		SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
		boolean music = getPrefs.getBoolean("checkbox", true);
		
		if (music)
		ourSong.start();
		
		
		Thread timer = new Thread() {
			public void run() {
				try {
					sleep(2000);

				} catch (InterruptedException e) {

					// set up alert message box
					AlertDialog.Builder dlgAlert = new AlertDialog.Builder(
							Splash.this);
					// exit
					dlgAlert.setMessage("Problem Displaying Splash Screen, Exit");
					dlgAlert.setTitle("Error");
					// if ok
					dlgAlert.setPositiveButton("OK",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {

									// Splash.this.finish();

								}
							});
					dlgAlert.setCancelable(true);
					dlgAlert.create().show();

					e.printStackTrace();

				} finally {
					Intent OpenCalc = new Intent("com.appforged.AppForged.Menu");
					startActivity(OpenCalc);
				}

			}

		};
		timer.start();

	}

	@Override
	protected void onPause() {
		super.onPause();
		ourSong.release();
		finish();
	}

}
